package com.lion.ball.app.common.application;

import android.content.Context;

import com.chris.dev.base.libs.v1.http.protocols.HttpHeader;
import com.chris.libs.base.x.mvpp.application.BaseApplication;
import com.chris.libs.devtools.x.v1.utils.GlideUtil;
import com.chris.libs.devtools.x.v1.utils.StorageUtil;
import com.chris.libs.devtools.x.v1.utils.UtilsManager;
import com.chris.libs.http.x.v1.NetApi;
import com.chris.libs.http.x.v1.constants.SPKeys;
import com.chris.libs.http.x.v1.normal.DefaultRetrofit;
import com.lion.ball.base.constants.Urls;

import java.util.Random;

/**
 * @author Chris chan
 * Create on： 2025/2/1 9:59
 * Use for:
 * Explain:
 */
public class CupApplication extends BaseApplication {
    @Override
    protected void init() {
        DefaultRetrofit.setBaseUrl(Urls.BASE_URL);
        GlideUtil.setImageUrlPrefix(Urls.FILE_URL);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        UtilsManager.init(base);
        initNetProtocol();

        // 放置模拟token
        StorageUtil.save(SPKeys.ACCESS_TOKEN,"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyQ29kZSI6NzU2ODMxNzEyNzIxMzc1MjMyLCJhdXRob3JpdGllcyI6WyJVU0VSIl0sInVzZXJuYW1lIjoi5LiA5Yy554u8MTIzIiwic3ViIjoi5LiA5Yy554u8MTIzIiwiaWF0IjoxNzU4MjgxMzEzLCJleHAiOjIzNjMwODEzMTN9.ZatdYdDg8XqQvM2aHbRNYf19TCrFuRdLW6D7jsC69mw");
    }

    /**
     * 初始化网络协议
     */
    private void initNetProtocol() {
        HttpHeader httpHeader = HttpHeader.create()
                .setOs("Android")
                .setVer("1.0.0")
                .setChannel("OPPO")
                .setAppId("Worker")//应该采用算法加密
                .setAppSecret("Worker Android");//应该采用算法加密
        // 业务干预修改经纬度
        NetApi.PostHeaderCallback callback = header -> {
            long lng1 = new Random().nextInt(1000000);
            long lat1 = new Random().nextInt(1000000);
            header.setLng(107000000L + lng1);
            header.setLat(33000000L + lat1);
        };
        NetApi.initHeader(httpHeader, callback);
    }
}
